﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ImageConverter.Model;
using ImageConverter.Model.Enums;

namespace ImageConverter.Utils
{
    public class EntryContainerLocator : IEntryContainerLocator
    {
        public static readonly string ZipExtensionMask = "*.zip";
        public static readonly string RarExtensionMask = "*.rar";

        #region IEntryContainerLocator Members

        public IEnumerable<ContainerItem> Locate(string lookupPath)
        {
            switch (productType)
            {
                case ContainerTypeEnum.Zip:
                    return FileSearchUtil.GetItems(lookupPath, ZipExtensionMask);
                case ContainerTypeEnum.Folders:
                    return Directory.GetDirectories(lookupPath).Select(di => new ContainerItem(di,true));
                case ContainerTypeEnum.Rar:
                    return FileSearchUtil.GetItems(lookupPath, RarExtensionMask);
                default:
                    throw new NotSupportedException("Illegal container type: " + productType.ToString());
            }
        }

        public void SetContainerType(ContainerTypeEnum productType)
        {
            this.productType = productType;
        }

        #endregion

        private ContainerTypeEnum productType;
    }
}
